package com.world.common.generate.auto;


import net.sf.json.JSONObject;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class QFieldInfo {
    private String name;
    private String nickname;
    private Integer length;
    private QFieldType type;
    private String javaFiledType;
    private Boolean nullable = true;
    private String validType;
    private String format;
    private Action[] actions;
    private List<String> exportList = new ArrayList<>();
    private Map<String, String> dictMap = new HashMap<>();
    private Map map;

    public void fromQField(Field field, QField qField) {
        this.name = field.getName();
        this.nickname = qField.name();
        this.type = qField.type();
        this.nullable = qField.nullable();
        this.setJavaFiledType(field.getType().getSimpleName());
        switch (qField.type()) {
            case text:
                break;
            case textarea:
                break;
            case date:
                this.format = qField.format();
                break;
            case dict:
                if (QFieldDictType.common.equals(qField.dictType())) {
                    JSONObject jsonObject = JSONObject.fromObject(qField.dictValues());
                    for (Object o : jsonObject.entrySet()) {
                        Map.Entry entry = (Map.Entry) o;
                        dictMap.put((String) entry.getKey(), (String) entry.getValue());
                    }
                }
                if (QFieldDictType.dynamic.equals(qField.dictType())) {
                    //todo:
                }
                break;
        }

    }

    //---------------get/set------------------------------------------------

    public String getJavaFiledType() {
        return javaFiledType;
    }

    public void setJavaFiledType(String javaFiledType) {
        this.javaFiledType = javaFiledType;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public Integer getLength() {
        return length;
    }

    public void setLength(Integer length) {
        this.length = length;
    }

    public QFieldType getType() {
        return type;
    }

    public void setType(QFieldType type) {
        this.type = type;
    }

    public Boolean getNullable() {
        return nullable;
    }

    public void setNullable(Boolean nullable) {
        this.nullable = nullable;
    }

    public String getValidType() {
        return validType;
    }

    public void setValidType(String validType) {
        this.validType = validType;
    }

    public String getFormat() {
        return format;
    }

    public void setFormat(String format) {
        this.format = format;
    }

    public Action[] getActions() {
        return actions;
    }

    public void setActions(Action[] actions) {
        this.actions = actions;
    }

    public List<String> getExportList() {
        return exportList;
    }

    public void setExportList(List<String> exportList) {
        this.exportList = exportList;
    }

    public Map getMap() {
        return map;
    }

    public void setMap(Map map) {
        this.map = map;
    }

    public Map<String, String> getDictMap() {
        return dictMap;
    }

    public void setDictMap(Map<String, String> dictMap) {
        this.dictMap = dictMap;
    }
}
